﻿using RpcClient.Interface;
using RpcModel;

namespace RpcClient.Tran.Tcc
{
    internal class TccNoParamBasicTemplate : ITranTemplate
    {

        private readonly IUnityCollect _Unity = null;

        /// <summary>
        /// 事务模板
        /// </summary>
        /// <param name="name">事务名</param>
        public TccNoParamBasicTemplate(string name)
        {
            this.TranMode = RpcTranMode.Tcc;
            this.TranName = name;
            this._Unity = RpcClient.Unity;
        }
        /// <summary>
        /// 事务名
        /// </summary>
        public string TranName
        {
            get;
        }
        /// <summary>
        /// 事务执行方式
        /// </summary>
        public RpcTranMode TranMode
        {
            get;
            set;
        }
        /// <summary>
        /// 提交事务
        /// </summary>
        /// <param name="submitJson"></param>
        /// <param name="extend"></param>
        public void Commit(string submitJson, string extend)
        {
            IRpcTranEvent action = this._Unity.Resolve<IRpcTranEvent>(this.TranName);
            action.Commit();
        }
        /// <summary>
        /// 回滚
        /// </summary>
        /// <param name="json"></param>
        /// <param name="extend"></param>
        public void Rollback(string json, string extend)
        {
            IRpcTranEvent action = this._Unity.Resolve<IRpcTranEvent>(this.TranName);
            action.Rollback();
        }
    }
}
